/**
 * 
 */
package org.seckill.web;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import org.seckill.service.SysAreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * @author yue
 * 2016年8月6日 下午5:57:24
 */
@Controller
@RequestMapping("/tree")
public class TreeController {
	
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private SysAreaService sysAreaService;
	
	@RequestMapping(value="/page",method=RequestMethod.GET)
	public String getpage(){
		return "tree";
	}
	
	@RequestMapping(value="/list",method=RequestMethod.GET,produces={"application/json"})
	@ResponseBody
	public String getTreeList(){
		StringBuilder ss = null;
		try {
			File file = ResourceUtils.getFile("classpath:tree_data1.json");
			BufferedReader br = new BufferedReader(new FileReader(file));
			ss =new StringBuilder();
			String line = null;
			while((line = br.readLine()) != null){
				ss.append(line);
			}
			br.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return ss.toString();
	}
	
	@RequestMapping(value="/areaList",produces={"application/json;charset=utf-8"})
	@ResponseBody
	public String getAreaList(@RequestParam(value="id",required=false)String code){
		String result = null;
		try {
			result = sysAreaService.getTreeJsonDate(code);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		logger.info("返回列表：{}",result);
		return result;
	}

	
	
}
